package com.dingup.provider.service.student.impl;

import com.dingup.api.Util.DateUtil;
import com.dingup.api.model.student.StudentSchoolInformation;
import com.dingup.provider.mapper.StudentSchoolInformationMapper;
import com.dingup.provider.service.student.StudentSchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by wancheng on 2018/8/15.
 */
@Service
public class StudentSchoolServiceImpl implements StudentSchoolService {

    private static final String OTHER = "其他";

    private static final String SPLIT_STRING = "-";

    @Autowired
    StudentSchoolInformationMapper studentSchoolInformationMapper;
    @Override
    public void saveStudentSchool(StudentSchoolInformation studentSchoolInformation) {
        studentSchoolInformationMapper.insertSelective(studentSchoolInformation);
    }

    @Override
    public StudentSchoolInformation getStudentSchoolInformationByStudentId(String studentId) {
        StudentSchoolInformation studentSchoolInformation = studentSchoolInformationMapper.getSchoolByUserId(studentId);
        if (studentSchoolInformation != null){
            String countryTarget = studentSchoolInformation.getCountryTarget();
            if (countryTarget.contains(SPLIT_STRING)){
                String[] country = countryTarget.split(SPLIT_STRING);
                studentSchoolInformation.setCountryTarget(country[0]);
                if (country.length >= 2){
                    studentSchoolInformation.setOtherCountry(country[1]);
                }
            }
            studentSchoolInformation.setCreateTimeString(DateUtil.date2Str(studentSchoolInformation.getCreateTime()));
            studentSchoolInformation.setUpdateTimeString(DateUtil.date2Str(studentSchoolInformation.getUpdateTime()));
        }
        return studentSchoolInformation;
    }

    @Override
    public void updateSchoolInformation(StudentSchoolInformation studentSchoolInformation) {
        studentSchoolInformationMapper.updateByPrimaryKeySelective(studentSchoolInformation);
    }


}
